package com.jzx.provider.cv.service;

import com.hankcs.hanlp.dictionary.CustomDictionary;
import com.jzx.provider.cv.model.ComName;
import com.jzx.provider.cv.repository.ComNameRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class ComNameService {
    @Autowired
    private ComNameRepository comRepository;

    public void createDir() {
        for (int i = 1; i < 1000; i++) {
            List<ComName> coms = comRepository.findByPage((i - 1) * 100, 100);
            if (coms == null || coms.size() == 0) {
                return;
            }
            coms.forEach(com -> {
                CustomDictionary.insert(com.getName(), com.getType() + " " + com.getWeight());
                if(!StringUtils.isEmpty(com.getShortName())){
                    String[] shorts=com.getShortName().split(",");
                    for(String shortName:shorts){
                        CustomDictionary.insert(shortName, com.getType() + " " + com.getWeight());
                    }
                }
            });
        }
    }
}
